// execute these functions when all scripts are loaded
head.ready(function(){
	lga_bredcrumbs.init();
});

/* jQuery vertical align function
 * usage: $('selector').vAlign();
*/
(function ($) {
	$.fn.vAlign=function(){return this.each(function(){var a=$(this).height(),b=$(this).parent().height(),a=Math.ceil((b-a)/2);$(this).css("padding-top",a)})};
})(jQuery);

/* jQuery clear form
 * usage: $('selector').clearForm();
*/
$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form'){
			return $(':input',this).clearForm();
		}
		if (type == 'text' || type == 'password' || tag == 'textarea'){
			this.value = '';
		}
		else if (type == 'checkbox' || type == 'radio'){
			this.checked = false;
		}
		else if (tag == 'select') {
			this.selectedIndex = -1;
		}
	}).trigger("liszt:updated");
};

/* TextAreaExpander plugin for jQuery
 * By Craig Buckler, Optimalworks.net
 * Assign a class of "expandMIN-MAX" to set the <textarea> minimum and maximum height
*/

(function(b){b.fn.TextAreaExpander=function(e,f){function c(a){var a=a.target||a,b=a.value.length,c=a.offsetWidth;if(b!=a.valLength||c!=a.boxWidth){if(g&&(b<a.valLength||c!=a.boxWidth))a.style.height="0px";var d=Math.max(a.expandMin,Math.min(a.scrollHeight,a.expandMax));a.style.overflow=a.scrollHeight>d?"auto":"hidden";a.style.height=d+"px";a.valLength=b;a.boxWidth=c}return!0}var g=!(b.browser.msie||b.browser.opera);this.each(function(){if(this.nodeName.toLowerCase()=="textarea"){var a=this.className.match(/expand(\d+)\-*(\d+)*/i); this.expandMin=e||(a?parseInt("0"+a[1],10):0);this.expandMax=f||(a?parseInt("0"+a[2],10):99999);c(this);if(!this.Initialized)this.Initialized=!0,b(this).css("padding-top",0).css("padding-bottom",0),b(this).bind("keyup",c).bind("focus",c)}});return this}})(jQuery);
jQuery(document).ready(function(){jQuery("textarea[class*=expand]").TextAreaExpander()});

//serialize form
(function($,a){$.fn.serializeObject=function(){var b={};$.each(this.serializeArray(),function(d,e){var f=e.name,c=e.value;b[f]=b[f]===a?c:$.isArray(b[f])?b[f].concat(c):[b[f],c]});return b}})(jQuery);
		

// clear form
lga_clearForm = {
	init: function() {
		$('.clear_form').click(function() {
			var clear_btn = $(this);
			$.fancybox(
				'<div class="tac"><p class="sepH_b">Are you sure you want to reset the form?</p><a href="javascript:void(0)" id="clear_yes" class="btn btn_d sepV_a">Yes</a><a href="javascript:void(0)" id="clear_no" class="btn btn_a">No</a></div>',
				{
					'transitionIn'		: 'elastic',
					'showCloseButton'	: false,
					'overlayOpacity'	: '0',
					'hideOnOverlayClick': false,
					'autoDimensions'	: false,
					'width'         	: 350,
					'height'        	: 'auto',
					'onComplete'	:	function() {
						$('#clear_yes').click(function(){
							clear_btn.closest('form').clearForm();
							tinyMCE.activeEditor.setContent(''); //clear tinyMCE content
							if(typeof form_a_validator != 'undefined') {
								form_a_validator.resetForm(); //reset validator when clearing form
								clear_btn.closest('form').find('div.error').removeClass('error');
							}
							if(typeof form_b_validator != 'undefined') {
								form_b_validator.resetForm(); //reset validator when clearing form
								clear_btn.closest('form').find('div.error').removeClass('error');
							}
							$.fancybox.close(); //close modal
							
						});
						$('#clear_no').click(function(){
							$.fancybox.close(); //close modal
						});
					}
				}
			);
			return false;
		});
	}
};



// jQuery Tools tabs (.tabs changed to .flowtabs to avoid conflict with Jquery UI tabs)
lga_flowTabs = {
	tabs_b: function() {
		$(".tabsB").flowtabs("div.content_panes > div");
	}
};





// FusionCharts
lga_fusionCharts = {
	
	chart_h: function() {
		var chart_h = new FusionCharts("lib/fusion-charts/charts/FCF_MSColumn2DLineDY.swf", "chart_h", "660", "300");
		chart_h.setDataURL("lib/fusion-charts/data/RainfallCanberra.xml");
		chart_h.setTransparent(true);
		chart_h.render("chart_h");
	},
	chart_k: function() {
		var chart_k = new FusionCharts("lib/fusion-charts/charts/FCF_StackedArea2D.swf", "chart_k", "660", "300");
		chart_k.setDataURL("lib/fusion-charts/data/RainfallBathurst.xml");
		chart_k.setTransparent(true);
		chart_k.render("chart_k");
	},
	chart_l: function() {
		var chart_l = new FusionCharts("lib/fusion-charts/charts/FCF_MSColumn2DLineDY.swf", "chart_l", "660", "300");
		chart_l.setDataURL("lib/fusion-charts/data/RainfallWaggaWagga.xml");
		chart_l.setTransparent(true);
		chart_l.render("chart_l");
	},
	chart_m: function() {	
		var chart_m = new FusionCharts("lib/fusion-charts/charts/FCF_MSColumn2DLineDY.swf", "chart_m", "660", "300");
		chart_m.setDataURL("lib/fusion-charts/data/TemperatureBathurst.xml");
		chart_m.setTransparent(true);
		chart_m.render("chart_m");
	},
	chart_n: function() {
		var chart_n = new FusionCharts("lib/fusion-charts/charts/FCF_MSColumn2DLineDY.swf", "chart_n", "660", "300");
		chart_n.setDataURL("lib/fusion-charts/data/TemperatureCanberra.xml");
		chart_n.setTransparent(true);
		chart_n.render("chart_n");
	},
	chart_o: function() {
		var chart_o = new FusionCharts("lib/fusion-charts/charts/FCF_StackedArea2D.swf", "chart_o", "660", "300");
		chart_o.setDataURL("lib/fusion-charts/data/TemperatureWaggaWagga.xml");
		chart_o.setTransparent(true);
		chart_o.render("chart_o");
	}
	
};
 





// jQuery UI datepicker
lga_datepicker = {
	init: function() {
		$( "input.datepicker" ).datepicker();
	}
};




// jQuery text truncate
lga_textTruncate = {
	init: function() {
		$('.truncate').textOverflow('...', true);
	}
};

// select box enhance
lga_selectBox = {
	init: function() {
		$(".chzn-select").chosen();
	}
};


// form serialize and submit
lga_formSubmit = {
	init: function() {
		$('form.js_submit').each(function(){
			$(this).submit(function() {
				var post = $(this).serializeObject();
				$.post('helper_serialize.php', post, function(data) {
					alert(data);
				});
				return false;
			});
		})
	}
};

//timepicker
lga_timepicker = {
	init: function() {
		$('#timepicker').datetimepicker();
	}
};


